package com.itheima.pool;

import java.util.concurrent.*;

public class Demo04 {

    public static void main(String[] args) throws InterruptedException {

        ThreadPoolExecutor pool = new ThreadPoolExecutor(
                5,
                10,
                60,
                TimeUnit.SECONDS,
               new ArrayBlockingQueue<>(5),
                Executors.defaultThreadFactory(),
               new ThreadPoolExecutor.DiscardOldestPolicy()
        );

// new  ThreadPoolExecutor.AbortPolicy()  丢弃并报错
        //  new ThreadPoolExecutor.DiscardPolicy() 直接丢弃
        /// new ThreadPoolExecutor.CallerRunsPolicy()
        for (int i = 1; i <= 50; i++) {
            int j=i;
            pool.submit(()->{
                System.out.println(j+"任务被"+Thread.currentThread().getName()+"执行了");
        });

        }
    }
}
